<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of promotion_m
 *
 * @author Gidaff_01
 */
class Promotion_m extends Model{
    //put your code here
    function Promotion_m() {
        parent::Model();
        $this->load->database();
    }

    function get_all_promotion($per_page, $offset){
        $this->db->select();
        $this->db->from('zoo_promotion');
        $this->db->limit($per_page, $offset);
        $query = $this->db->get();
        return $query->result_array();
    }

    function count_all_promotion(){
        $this->db->select('
            zoo_promotion.id,
            zoo_promotion.pct,
            zoo_promotion.`code`,
            zoo_promotion.qty,
            zoo_method_paiement.nom
        ');
        $this->db->from('zoo_promotion ,zoo_method_paiement');
        $this->db->where('zoo_promotion.type = zoo_method_paiement.id');
        $query = $this->db->get();
        return count($query->result_array());
    }

    function delete_promotion($promotion_id){
        return $this->db->delete('zoo_promotion', array('id' => $promotion_id));
    }

    function ajouter_promotion($data){
        return $this->db->insert('zoo_promotion',$data);
    }

    function update_promotion($data,$promotion_id){
        return $this->db->update('zoo_promotion',$data,array('id' => $promotion_id));
    }
    function is_code_existe($code) {
        return $this->db->get_where('zoo_promotion', array('code' => $code));
    }

    function get_promotion_by_id($promotion_id){
        $this->db->select();
        $this->db->from('zoo_promotion');
        $this->db->where('id', $promotion_id);
        $query = $this->db->get();
        return $query;
    }
}
?>
